
 ;
 ;                         LISTOPR.S
 ;
 ;              Program to perform various list operations
 ;


 ; Display a list

 ( define DISP-LIST
   ( lambda ( list )
     ( display list 'console )
    )
  )

 ; AVERAGE of a list

 ( define AVERAGE
   ( lambda ( list )
     ( if ( null? list )
         0
       ( / ( ADD-LIST list ) ( LENGTH-LIST list ) )
      )
    )
  )

 ; Multiplication of all elements of a list

 ( define MUL-LIST
   ( lambda ( list )
     ( if ( null? list )
         1
       ( * ( car list ) ( MUL-LIST ( cdr list ) ) )
      )
    )
  )

 ; Sum of elements of a list

 ( define ADD-LIST
   ( lambda ( list )
     ( if ( null? list )
         0
       ( + ( car list ) ( ADD-LIST ( cdr list ) ) )
      )
    )
  )

 ; Length of list

 ( define length-list
   ( lambda ( list )
     ( if ( null? list )
         0
       ( + 1 ( LENGTH-LIST ( cdr list ) ) )
      )
    )
  )

 ; Get an element of a list

 ( define GETN
   ( lambda ( list NUMBER )
     ( if ( null? list )
         0
       ( if ( = n 1 )
           ( car list )
         ( GETN ( cdr list ) ( - NUMBER 1 ) )
        )
      )
    )
  )

 ;  AVERAGE of list / Element of a list

 ( define AVG-DIV-NO
   ( lambda ( list NUMBER )
     ( / ( AVERAGE list ) ( GETN list NUMBER ) )
    )
  )

 ; Sum of list / Element of a list

 ( define ADD-DIV-NO
   ( lambda ( list NUMBER )
     ( / ( ADD-LIST list ) ( GETN list NUMBER ) )
    )
  )

 ; M-AVERAGE of list / Element of a list

 ( define M-AVG-DIV-NO
   ( lambda ( list NUMBER )
     ( / ( M-AVERAGE list ) ( GETN list NUMBER ) )
    )
  )

 ; Multiplication of list / Element of a list

 ( define MUL-DIV-NO
   ( lambda ( list NUMBER )
     ( / ( MUL-LIST list ) ( GETN list NUMBER ) )
    )
  )

 ; AVERAGE of list * Element of a list

 ( define AVG-MUL-NO
   ( lambda ( list NUMBER )
     ( * ( AVERAGE list ) ( GETN list NUMBER ) )
    )
  )

 ; Sum of list * Element of a list

 ( define ADD-MUL-NO
   ( lambda ( list NUMBER )
     ( * ( ADD-LIST list ) ( GETN list NUMBER ) )
    )
  )

 ; M-AVERAGE of list * Element of a list

 ( define M-AVG-MUL-NO
   ( lambda ( list NUMBER )
     ( * ( M-AVERAGE list ) ( GETN list NUMBER ) )
    )
  )

 ; Multiplication of list * Element of a list

 ( define MUL-MUL-NO
   ( lambda ( list NUMBER )
     ( * ( MUL-LIST list ) ( GETN list NUMBER ) )
    )
  )

 ; Multiply all elements of a list / no of elements in list

 ( define M-AVERAGE
   ( lambda ( list )
     ( if ( null? list )
         1
       ( / ( MUL-LIST list ) ( LENGTH-LIST list ) )
      )
    )
  )
